package com.flyxiaozhu.erp.core.entities;

import com.flyxiaozhu.erp.core.pojos.GoodsTagsPojo;
import lombok.Data;
import org.hibernate.annotations.*;

import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;

/**
 * @author flyxiaozhu
 * @date 2019-04-12 0:20
 */
@Entity
@Data
@DynamicInsert
@DynamicUpdate
@NamedNativeQueries({
        @NamedNativeQuery(
                name = "GoodsTag.getTagedGoodsByTagsIdIn",
                query = "SELECT * FROM goods_tags WHERE tags_id in ?1",
                resultSetMapping = "tagedGoods"
        ),
        @NamedNativeQuery(
                name = "GoodsTag.getTagedGoodsByGoodsIdIn",
                query = "SELECT * FROM goods_tags WHERE goods_id in ?1",
                resultSetMapping = "tagedGoods"
        ),
        @NamedNativeQuery(
                name = "GoodsTag.getTagedGoodsByTagsId",
                query = "SELECT * FROM goods_tags WHERE tags_id = ?1",
                resultSetMapping = "tagedGoods"
        )
})
@SqlResultSetMapping(name = "tagedGoods",
        classes = @ConstructorResult(
                targetClass = GoodsTagsPojo.class,
                columns = {
                        @ColumnResult(name = "goods_id", type = Long.class),
                        @ColumnResult(name = "tags_id", type = Long.class)
                }
        )
)
public class GoodsTag extends BaseEntity {
    @Column(columnDefinition = "varchar(32) not null default '' comment '标签名称'")
    private String title;

    @Column(columnDefinition = "varchar(32) not null default '' comment '颜色'")
    private String color;

    @Column(columnDefinition = "TIMESTAMP COMMENT '更新时间'")
    private String updateTime;
}
